using System;

namespace CodeLines.CodeIgnoreRules
{
    internal class StartWith : ICodeIgnoreRule
    {
        private string _rule;

        public bool SetRule(string rule)
        {
            if (string.IsNullOrWhiteSpace(rule)) return false;
            if (rule.EndsWith("*") && rule.Length > 1)
            {
                _rule = rule.Substring(0, rule.Length - 1);
                return true;
            }

            return false;
        }

        public bool IsIgnore(string code)
        {
            if (string.IsNullOrWhiteSpace(code)) return true;
            return code.StartsWith(_rule, StringComparison.OrdinalIgnoreCase);
        }


        public override string ToString()
        {
            return $"StartWith {_rule}";
        }
    }
}
